import os
import time
from appium import webdriver

# com.android.launcher3/.Launcher   锁屏页面
from appium.webdriver.common.touch_action import TouchAction

# com.android.dialer/.DialtactsActivity     电话记录页面
de = dict()
de['platformName'] = 'Android'
de['platformVersion'] = '5.1'
de['deviceName'] = '192.168.247.101:5555'
de['appPackage'] = 'com.android.dialer'
de['appActivity'] = '.DialtactsActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub', de)
driver.implicitly_wait(3)

# 1.1先获取屏幕宽度
window_size = driver.get_window_size()
print(window_size)

# 1.2 手机截图
# driver.get_screenshot_as_file(os.getcwd() + os.sep + './screen.png')

# 1.3 获取和设置手机网络【掌握】
# 1.3.1 获取手机网络
print(driver.network_connection)

# 1.3.2 设置手机网络  设置当前设备为飞行模式
# driver.set_network_connection(1)
# driver.set_network_connection(0)

# 1.4 发送键到设备
# 点击三次音量加，再点击返回，再点击两次音量减。
# driver.press_keycode(24)
# driver.press_keycode(24)
# driver.press_keycode(24)
# driver.press_keycode(4)
# driver.press_keycode(25)
# driver.press_keycode(25)

# 1.5 操作手机通知栏
# 打开通知栏，两秒后，关闭通知栏
driver.open_notifications()
time.sleep(2)
driver.press_keycode(4)




time.sleep(3)
driver.quit()
